<template>
	<view id="header-top">
		<view class="content-header">
			<view class="header">
				<view class="left">
					<image class="menu-icon" @click="getPage()" src="/static/categroy_icon_01.png" mode=""></image>
					<view class="header-title">Chain Life</view>
				</view>
				<view class="right">
					<!-- <image src="/static/mine_icon_01.png"  @click="toRoute('pages/member/index/index')" class="menu-icon" mode=""></image> -->
					<!-- <image src="/static/tabbar/member_index_selected.png" v-show="curRoute == 'pages/member/index/index'"  class="me-icon" mode=""></image> -->
          <image src="/static/icon/switch.png"  @click="switchLanguage" class="menu-icon" style="border-radius: unset"></image>
          <image src="/static/cart_icon_01.png" @click="toRoute('pages/goods/cart/cart')"  class="menu-icon" style="border-radius: unset"></image>
					<!-- <image src="/static/tabbar/cart_selected.png" v-show="curRoute == 'pages/goods/cart/cart'"  class="cart-icon" mode=""></image> -->
        </view>
			</view>
		</view>
	</view>
</template>

<script>
import Lang from '@/common/js/lang.js'
export default {
	data() {
		return {
			curRoute: '',
      langList: [],
		};
	},
	created(){
		this.curRoute = this.getPages();
  },
  mounted(){
    this.initLang();
  },
	onLoad() {
		
	},
	components: {

	},
	onShow() {

	},
	methods: {
    initLang() {
      //获取语言列表
      this.langList = this.$langConfig.list();
      if (!uni.getStorageSync("lang")) {
        this.langIndex = 0;
      } else {
        for (let i = 0; i < this.langList.length; i++) {
          if (this.langList[i].value == uni.getStorageSync("lang")) {
            this.langIndex = i;
            break;
          }
        }
      }
      this.$langConfig.refresh();
    },
	  // 切换语言
    switchLanguage(){
      let self = this;
      let newArray = [];
      for (let i = 0; i < this.langList.length; i++) {
        newArray.push(this.langList[i].name)
      }
      uni.showActionSheet({
        itemList: newArray,
        success: function(res) {
          if (self.langIndex != res.tapIndex) {
            self.$langConfig.change(self.langList[res.tapIndex].value)
          }
        }
      });
      // uni.showModal({
      //   title: '切换语言',
      //   content: '确认英文吗？',
      //   success: res => {
      //     if (res.confirm) {
      //       Lang.change('en-us')
      //       this.delFollow(e.collect_id, index);
      //     }
      //   }
      // })
    },
		// 获取当前路由
		getPages(){
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			return routes[routes.length - 1].route //获取当前页面路由
		},
		// 跳转路由
		toRoute(url){
			// if(this.curRoute == url) return false;
			uni.reLaunch({
				url: '/'+url,
			})
		},
		getPage(){			
			// if(this.curRoute != 'pages/index/index/index'){ // 如果不是首页 跳转到哪去？
			// 	uni.reLaunch({
			// 		url: '/pages/index/index/index'
			// 	})
			// }else { // 首页显示弹框
			// 	console.log('显示弹框')
			// }
			uni.navigateTo({
				url: '/pages/goods/category/category'
			})
		},
	}
};
</script>

<style scoped lang="scss">
	.content-header {
		width: 100%;
		height: 88upx;
		background: #fff;
		position: fixed;
		top: 0px;
		left: 0px;
		padding: 0px 40upx;
		box-sizing: border-box;
		z-index: 111;
		.header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 100%;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-size: 36upx;
			font-weight: 600;
			color: #020202;
			.header-title {
				text-align: center;
				margin-left: 24upx;
			}
			.left {
				display: flex;
				align-items: center;
			}
			.menu-icon {
				width: 48upx;
				height: 48upx;
			}
			.right {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				.menu-icon {
					border-radius: 50%;
					margin-left: 36upx;
				}
			}
		}
	}
</style>
